#ifndef xpack_test_math_index_system
#define xpack_test_math_index_system
#pragma push_macro("xuser")
#undef  xuser
#define xuser mixc::test_math_index_system::inc
#include"test/helper.hpp" // 需要放第一
#include"math/index_system.hpp"
#pragma pop_macro("xuser")

namespace mixc::test_math_index_system{
    xtest("index_system"){
        #define xgen(SPAN,LENGTH,RESULT,LEFT,RIGHT)             \
            do{                                                 \
                auto span = SPAN;                               \
                auto result = span.normalize(LENGTH);           \
                xassert_eq(RESULT, result);                     \
                if (RESULT == bstate_t::fail){ break; }         \
                xassert_eq(uxx(LEFT) ,  span->left);            \
                xassert_eq(uxx(RIGHT),  span->right);           \
            }while(0)

        xgen(cc(+0, +0), 0, bstate_t::fail   , 0, 0);
        xgen(co(+0, +0), 0, bstate_t::fail   , 0, 0);
        xgen(oc(+0, +0), 0, bstate_t::fail   , 0, 0);
        xgen(oo(+0, +0), 0, bstate_t::fail   , 0, 0);

        xgen(cc(+0, +0), 1, bstate_t::success, 0, 0);
        xgen(co(+0, +0), 1, bstate_t::fail   , 0, 0);
        xgen(oc(+0, +0), 1, bstate_t::fail   , 0, 0);
        xgen(oo(+0, +0), 1, bstate_t::fail   , 0, 0);

        xgen(cc(+0, +0), 2, bstate_t::success, 0, 0);
        xgen(co(+0, +0), 2, bstate_t::fail   , 0, 0);
        xgen(oc(+0, +0), 2, bstate_t::fail   , 0, 0);
        xgen(oo(+0, +0), 2, bstate_t::fail   , 0, 0);

        xgen(cc(+0, +0), 3, bstate_t::success, 0, 0);
        xgen(co(+0, +0), 3, bstate_t::fail   , 0, 0);
        xgen(oc(+0, +0), 3, bstate_t::fail   , 1, 0);
        xgen(oo(+0, +0), 3, bstate_t::fail   , 0, 0);

        xgen(cc(+0, +0), 4, bstate_t::success, 0, 0);
        xgen(co(+0, +0), 4, bstate_t::fail   , 0, 0);
        xgen(oc(+0, +0), 4, bstate_t::fail   , 0, 0);
        xgen(oo(+0, +0), 4, bstate_t::fail   , 0, 0);




        xgen(cc(+0, +1), 0, bstate_t::fail   , 0, 0);
        xgen(co(+0, +1), 0, bstate_t::fail   , 0, 0);
        xgen(oc(+0, +1), 0, bstate_t::fail   , 0, 0);
        xgen(oo(+0, +1), 0, bstate_t::fail   , 0, 0);

        xgen(cc(+0, +1), 1, bstate_t::fail   , 0, 0);
        xgen(co(+0, +1), 1, bstate_t::success, 0, 0);
        xgen(oc(+0, +1), 1, bstate_t::fail   , 0, 0);
        xgen(oo(+0, +1), 1, bstate_t::fail   , 0, 0);

        xgen(cc(+0, +1), 2, bstate_t::success, 0, 1);
        xgen(co(+0, +1), 2, bstate_t::success, 0, 0);
        xgen(oc(+0, +1), 2, bstate_t::success, 1, 1);
        xgen(oo(+0, +1), 2, bstate_t::fail   , 0, 0);

        xgen(cc(+0, +1), 3, bstate_t::success, 0, 1);
        xgen(co(+0, +1), 3, bstate_t::success, 0, 0);
        xgen(oc(+0, +1), 3, bstate_t::success, 1, 1);
        xgen(oo(+0, +1), 3, bstate_t::fail   , 0, 0);

        xgen(cc(+0, +1), 4, bstate_t::success, 0, 1);
        xgen(co(+0, +1), 4, bstate_t::success, 0, 0);
        xgen(oc(+0, +1), 4, bstate_t::success, 1, 1);
        xgen(oo(+0, +1), 4, bstate_t::fail   , 0, 0);




        xgen(cc(+0, +2), 0, bstate_t::fail   , 0, 0);
        xgen(co(+0, +2), 0, bstate_t::fail   , 0, 0);
        xgen(oc(+0, +2), 0, bstate_t::fail   , 0, 0);
        xgen(oo(+0, +2), 0, bstate_t::fail   , 0, 0);

        xgen(cc(+0, +2), 1, bstate_t::fail   , 0, 0);
        xgen(co(+0, +2), 1, bstate_t::fail   , 0, 0);
        xgen(oc(+0, +2), 1, bstate_t::fail   , 0, 0);
        xgen(oo(+0, +2), 1, bstate_t::fail   , 0, 0);

        xgen(cc(+0, +2), 2, bstate_t::fail   , 0, 0);
        xgen(co(+0, +2), 2, bstate_t::success, 0, 1);
        xgen(oc(+0, +2), 2, bstate_t::fail   , 0, 0);
        xgen(oo(+0, +2), 2, bstate_t::success, 1, 1);

        xgen(cc(+0, +2), 3, bstate_t::success, 0, 2);
        xgen(co(+0, +2), 3, bstate_t::success, 0, 1);
        xgen(oc(+0, +2), 3, bstate_t::success, 1, 2);
        xgen(oo(+0, +2), 3, bstate_t::success, 1, 1);

        xgen(cc(+0, +2), 4, bstate_t::success, 0, 2);
        xgen(co(+0, +2), 4, bstate_t::success, 0, 1);
        xgen(oc(+0, +2), 4, bstate_t::success, 1, 2);
        xgen(oo(+0, +2), 4, bstate_t::success, 1, 1);




        xgen(cc(+0, +3), 0, bstate_t::fail   , 0, 0);
        xgen(co(+0, +3), 0, bstate_t::fail   , 0, 0);
        xgen(oc(+0, +3), 0, bstate_t::fail   , 0, 0);
        xgen(oo(+0, +3), 0, bstate_t::fail   , 0, 0);

        xgen(cc(+0, +3), 1, bstate_t::fail   , 0, 0);
        xgen(co(+0, +3), 1, bstate_t::fail   , 0, 0);
        xgen(oc(+0, +3), 1, bstate_t::fail   , 0, 0);
        xgen(oo(+0, +3), 1, bstate_t::fail   , 0, 0);

        xgen(cc(+0, +3), 2, bstate_t::fail   , 0, 0);
        xgen(co(+0, +3), 2, bstate_t::fail   , 0, 0);
        xgen(oc(+0, +3), 2, bstate_t::fail   , 0, 0);
        xgen(oo(+0, +3), 2, bstate_t::fail   , 0, 0);

        xgen(cc(+0, +3), 3, bstate_t::fail   , 0, 0);
        xgen(co(+0, +3), 3, bstate_t::success, 0, 2);
        xgen(oc(+0, +3), 3, bstate_t::fail   , 0, 0);
        xgen(oo(+0, +3), 3, bstate_t::success, 1, 2);

        xgen(cc(+0, +3), 4, bstate_t::success, 0, 3);
        xgen(co(+0, +3), 4, bstate_t::success, 0, 2);
        xgen(oc(+0, +3), 4, bstate_t::success, 1, 3);
        xgen(oo(+0, +3), 4, bstate_t::success, 1, 2);







        xgen(cc(+1, +0), 0, bstate_t::fail   , 0, 0);
        xgen(co(+1, +0), 0, bstate_t::fail   , 0, 0);
        xgen(oc(+1, +0), 0, bstate_t::fail   , 0, 0);
        xgen(oo(+1, +0), 0, bstate_t::fail   , 0, 0);

        xgen(cc(+1, +0), 1, bstate_t::fail   , 0, 0);
        xgen(co(+1, +0), 1, bstate_t::fail   , 0, 0);
        xgen(oc(+1, +0), 1, bstate_t::success, 0, 0);
        xgen(oo(+1, +0), 1, bstate_t::fail   , 0, 0);

        xgen(cc(+1, +0), 2, bstate_t::success, 1, 0);
        xgen(co(+1, +0), 2, bstate_t::success, 1, 1);
        xgen(oc(+1, +0), 2, bstate_t::success, 0, 0);
        xgen(oo(+1, +0), 2, bstate_t::fail   , 0, 0);

        xgen(cc(+1, +0), 3, bstate_t::success, 1, 0);
        xgen(co(+1, +0), 3, bstate_t::success, 1, 1);
        xgen(oc(+1, +0), 3, bstate_t::success, 0, 0);
        xgen(oo(+1, +0), 3, bstate_t::fail   , 0, 0);

        xgen(cc(+1, +0), 4, bstate_t::success, 1, 0);
        xgen(co(+1, +0), 4, bstate_t::success, 1, 1);
        xgen(oc(+1, +0), 4, bstate_t::success, 0, 0);
        xgen(oo(+1, +0), 4, bstate_t::fail   , 0, 0);




        xgen(cc(+2, +0), 0, bstate_t::fail   , 0, 0);
        xgen(co(+2, +0), 0, bstate_t::fail   , 0, 0);
        xgen(oc(+2, +0), 0, bstate_t::fail   , 0, 0);
        xgen(oo(+2, +0), 0, bstate_t::fail   , 0, 0);

        xgen(cc(+2, +0), 1, bstate_t::fail   , 0, 0);
        xgen(co(+2, +0), 1, bstate_t::fail   , 0, 0);
        xgen(oc(+2, +0), 1, bstate_t::fail   , 0, 0);
        xgen(oo(+2, +0), 1, bstate_t::fail   , 0, 0);

        xgen(cc(+2, +0), 2, bstate_t::fail   , 0, 0);
        xgen(co(+2, +0), 2, bstate_t::fail   , 0, 0);
        xgen(oc(+2, +0), 2, bstate_t::success, 1, 0);
        xgen(oo(+2, +0), 2, bstate_t::success, 1, 1);

        xgen(cc(+2, +0), 3, bstate_t::success, 2, 0);
        xgen(co(+2, +0), 3, bstate_t::success, 2, 1);
        xgen(oc(+2, +0), 3, bstate_t::success, 1, 0);
        xgen(oo(+2, +0), 3, bstate_t::success, 1, 1);

        xgen(cc(+2, +0), 4, bstate_t::success, 2, 0);
        xgen(co(+2, +0), 4, bstate_t::success, 2, 1);
        xgen(oc(+2, +0), 4, bstate_t::success, 1, 0);
        xgen(oo(+2, +0), 4, bstate_t::success, 1, 1);




        xgen(cc(+3, +0), 0, bstate_t::fail   , 0, 0);
        xgen(co(+3, +0), 0, bstate_t::fail   , 0, 0);
        xgen(oc(+3, +0), 0, bstate_t::fail   , 0, 0);
        xgen(oo(+3, +0), 0, bstate_t::fail   , 0, 0);

        xgen(cc(+3, +0), 1, bstate_t::fail   , 0, 0);
        xgen(co(+3, +0), 1, bstate_t::fail   , 0, 0);
        xgen(oc(+3, +0), 1, bstate_t::fail   , 0, 0);
        xgen(oo(+3, +0), 1, bstate_t::fail   , 0, 0);

        xgen(cc(+3, +0), 2, bstate_t::fail   , 0, 0);
        xgen(co(+3, +0), 2, bstate_t::fail   , 0, 0);
        xgen(oc(+3, +0), 2, bstate_t::fail   , 0, 0);
        xgen(oo(+3, +0), 2, bstate_t::fail   , 0, 0);

        xgen(cc(+3, +0), 3, bstate_t::fail   , 0, 0);
        xgen(co(+3, +0), 3, bstate_t::fail   , 0, 0);
        xgen(oc(+3, +0), 3, bstate_t::success, 2, 0);
        xgen(oo(+3, +0), 3, bstate_t::success, 2, 1);

        xgen(cc(+3, +0), 4, bstate_t::success, 3, 0);
        xgen(co(+3, +0), 4, bstate_t::success, 3, 1);
        xgen(oc(+3, +0), 4, bstate_t::success, 2, 0);
        xgen(oo(+3, +0), 4, bstate_t::success, 2, 1);









        xgen(cc(+1, +1), 0, bstate_t::fail   , 0, 0);
        xgen(co(+1, +1), 0, bstate_t::fail   , 0, 0);
        xgen(oc(+1, +1), 0, bstate_t::fail   , 0, 0);
        xgen(oo(+1, +1), 0, bstate_t::fail   , 0, 0);

        xgen(cc(+1, +1), 1, bstate_t::fail   , 0, 0);
        xgen(co(+1, +1), 1, bstate_t::fail   , 0, 0);
        xgen(oc(+1, +1), 1, bstate_t::fail   , 0, 0);
        xgen(oo(+1, +1), 1, bstate_t::fail   , 0, 0);

        xgen(cc(+1, +1), 2, bstate_t::success, 1, 1);
        xgen(co(+1, +1), 2, bstate_t::fail   , 0, 0);
        xgen(oc(+1, +1), 2, bstate_t::fail   , 0, 0);
        xgen(oo(+1, +1), 2, bstate_t::fail   , 0, 0);

        xgen(cc(+1, +1), 3, bstate_t::success, 1, 1);
        xgen(co(+1, +1), 3, bstate_t::fail   , 0, 0);
        xgen(oc(+1, +1), 3, bstate_t::fail   , 0, 0);
        xgen(oo(+1, +1), 3, bstate_t::fail   , 0, 0);

        xgen(cc(+1, +1), 4, bstate_t::success, 1, 1);
        xgen(co(+1, +1), 4, bstate_t::fail   , 0, 0);
        xgen(oc(+1, +1), 4, bstate_t::fail   , 0, 0);
        xgen(oo(+1, +1), 4, bstate_t::fail   , 0, 0);




        xgen(cc(+2, +1), 0, bstate_t::fail   , 0, 0);
        xgen(co(+2, +1), 0, bstate_t::fail   , 0, 0);
        xgen(oc(+2, +1), 0, bstate_t::fail   , 0, 0);
        xgen(oo(+2, +1), 0, bstate_t::fail   , 0, 0);

        xgen(cc(+2, +1), 1, bstate_t::fail   , 0, 0);
        xgen(co(+2, +1), 1, bstate_t::fail   , 0, 0);
        xgen(oc(+2, +1), 1, bstate_t::fail   , 0, 0);
        xgen(oo(+2, +1), 1, bstate_t::fail   , 0, 0);

        xgen(cc(+2, +1), 2, bstate_t::fail   , 0, 0);
        xgen(co(+2, +1), 2, bstate_t::fail   , 0, 0);
        xgen(oc(+2, +1), 2, bstate_t::success, 1, 1);
        xgen(oo(+2, +1), 2, bstate_t::fail   , 0, 0);

        xgen(cc(+2, +1), 3, bstate_t::success, 2, 1);
        xgen(co(+2, +1), 3, bstate_t::success, 2, 2);
        xgen(oc(+2, +1), 3, bstate_t::success, 1, 1);
        xgen(oo(+2, +1), 3, bstate_t::fail   , 0, 0);

        xgen(cc(+2, +1), 4, bstate_t::success, 2, 1);
        xgen(co(+2, +1), 4, bstate_t::success, 2, 2);
        xgen(oc(+2, +1), 4, bstate_t::success, 1, 1);
        xgen(oo(+2, +1), 4, bstate_t::fail   , 0, 0);




        xgen(cc(+3, +1), 0, bstate_t::fail   , 0, 0);
        xgen(co(+3, +1), 0, bstate_t::fail   , 0, 0);
        xgen(oc(+3, +1), 0, bstate_t::fail   , 0, 0);
        xgen(oo(+3, +1), 0, bstate_t::fail   , 0, 0);

        xgen(cc(+3, +1), 1, bstate_t::fail   , 0, 0);
        xgen(co(+3, +1), 1, bstate_t::fail   , 0, 0);
        xgen(oc(+3, +1), 1, bstate_t::fail   , 0, 0);
        xgen(oo(+3, +1), 1, bstate_t::fail   , 0, 0);

        xgen(cc(+3, +1), 2, bstate_t::fail   , 0, 0);
        xgen(co(+3, +1), 2, bstate_t::fail   , 0, 0);
        xgen(oc(+3, +1), 2, bstate_t::fail   , 0, 0);
        xgen(oo(+3, +1), 2, bstate_t::fail   , 0, 0);

        xgen(cc(+3, +1), 3, bstate_t::fail   , 0, 0);
        xgen(co(+3, +1), 3, bstate_t::fail   , 0, 0);
        xgen(oc(+3, +1), 3, bstate_t::success, 2, 1);
        xgen(oo(+3, +1), 3, bstate_t::success, 2, 2);

        xgen(cc(+3, +1), 4, bstate_t::success, 3, 1);
        xgen(co(+3, +1), 4, bstate_t::success, 3, 2);
        xgen(oc(+3, +1), 4, bstate_t::success, 2, 1);
        xgen(oo(+3, +1), 4, bstate_t::success, 2, 2);







        xgen(cc(0, -1), 1, bstate_t::fail   , 0, 0);
        xgen(co(0, -1), 1, bstate_t::success, 0, 0);
        xgen(oc(0, -1), 1, bstate_t::fail   , 0, 0);
        xgen(oo(0, -1), 1, bstate_t::fail   , 0, 0);

        xgen(cc(0, -1), 2, bstate_t::fail   , 0, 0);
        xgen(co(0, -1), 2, bstate_t::success, 0, 1);
        xgen(oc(0, -1), 2, bstate_t::fail   , 0, 0);
        xgen(oo(0, -1), 2, bstate_t::success, 1, 1);

        xgen(cc(0, -1), 3, bstate_t::fail   , 0, 0);
        xgen(co(0, -1), 3, bstate_t::success, 0, 2);
        xgen(oc(0, -1), 3, bstate_t::fail   , 0, 0);
        xgen(oo(0, -1), 3, bstate_t::success, 1, 2);

        xgen(cc(0, -1), 4, bstate_t::fail   , 0, 0);
        xgen(co(0, -1), 4, bstate_t::success, 0, 3);
        xgen(oc(0, -1), 4, bstate_t::fail   , 0, 0);
        xgen(oo(0, -1), 4, bstate_t::success, 1, 3);







        xgen(cc(-1, 0), 1, bstate_t::fail   , 0, 0);
        xgen(co(-1, 0), 1, bstate_t::fail   , 0, 0);
        xgen(oc(-1, 0), 1, bstate_t::success, 0, 0);
        xgen(oo(-1, 0), 1, bstate_t::fail   , 0, 0);

        xgen(cc(-1, 0), 2, bstate_t::fail   , 0, 0);
        xgen(co(-1, 0), 2, bstate_t::fail   , 0, 0);
        xgen(oc(-1, 0), 2, bstate_t::success, 1, 0);
        xgen(oo(-1, 0), 2, bstate_t::success, 1, 1);

        xgen(cc(-1, 0), 3, bstate_t::fail   , 0, 0);
        xgen(co(-1, 0), 3, bstate_t::fail   , 0, 0);
        xgen(oc(-1, 0), 3, bstate_t::success, 2, 0);
        xgen(oo(-1, 0), 3, bstate_t::success, 2, 1);

        xgen(cc(-1, 0), 4, bstate_t::fail   , 0, 0);
        xgen(co(-1, 0), 4, bstate_t::fail   , 0, 0);
        xgen(oc(-1, 0), 4, bstate_t::success, 3, 0);
        xgen(oo(-1, 0), 4, bstate_t::success, 3, 1);

        #undef  xgen
    };
}

#endif
